package com.jindi.jacococli.biz.config;

import com.jindi.infra.tools.thread.EnhanceThreadPoolExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class ThreadPoolConfig {

    private static final Integer THREAD_SIZE = 10;
    private static final Long ALIVE_TIME = 10L;
    private static final Integer THREAD_SIZE_BATCH = 1;
    private static final Integer SONAR_THREAD_SIZE = 1;

    @Bean
    public EnhanceThreadPoolExecutor subBatchReportServiceTaskThreadPool() {
        return  new EnhanceThreadPoolExecutor(
                "SubJacocoReportServiceTask-Thread-Pool", THREAD_SIZE, THREAD_SIZE, ALIVE_TIME,
                TimeUnit.MINUTES, new LinkedBlockingDeque<>(), new ThreadPoolExecutor.AbortPolicy());

    }

    @Bean
    public EnhanceThreadPoolExecutor batchReportServiceTaskThreadPool() {
        return  new EnhanceThreadPoolExecutor(
                "JacocoReportServiceTask-Thread-Pool", THREAD_SIZE_BATCH, THREAD_SIZE_BATCH, ALIVE_TIME,
                TimeUnit.MINUTES, new LinkedBlockingDeque<>(), new ThreadPoolExecutor.AbortPolicy());

    }

    @Bean
    public EnhanceThreadPoolExecutor sonarTaskThreadPool() {
        return  new EnhanceThreadPoolExecutor(
                "sonarTaskThreadPool-Thread-Pool", SONAR_THREAD_SIZE, SONAR_THREAD_SIZE, ALIVE_TIME,
                TimeUnit.MINUTES, new LinkedBlockingDeque<>(), new ThreadPoolExecutor.AbortPolicy());

    }

}
